package cn.mesmile.clickhouse.controller;

import cn.mesmile.clickhouse.entity.Book;
import cn.mesmile.clickhouse.service.BookService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author zb
 * @date 2021/7/4 23:49
 * @Description
 */
@AllArgsConstructor
@RequestMapping("/api/v1/book")
@RestController
public class BookController {

    private final BookService bookService;

    @GetMapping("/get")
    public List<Book> get() throws Exception {
        Book book = bookService.selectByPrimaryKey(Book.class, 1);

        return bookService.select();
    }

    @GetMapping("/save")
    public int save() {
        Book book = new Book();
        book.setId(2L);
        book.setName("测试姓名2");
        book.setAuthor("测试作者2");
        book.setPublishDate(new Date());
        book.setPrice(200);
        book.setIsPublish(true);
        return bookService.save(book);
    }


}
